package io.renren.roomManager.service.impl;

import io.renren.roomManager.vo.UpdateStatusVo;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.roomManager.dao.BookingsDao;
import io.renren.roomManager.entity.BookingsEntity;
import io.renren.roomManager.service.BookingsService;


@Service("bookingsService")
public class BookingsServiceImpl extends ServiceImpl<BookingsDao, BookingsEntity> implements BookingsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BookingsEntity> wrapper =  new QueryWrapper<BookingsEntity>();
        String key = (String) params.get("key");

        if(!key.isEmpty()){
            wrapper.like("username",key);
        }

        IPage<BookingsEntity> page = this.page(
                new Query<BookingsEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void bookingsSave(BookingsEntity bookings) {
        /**
         * 0 待处理
         * 1 已批准
         * 2 已拒绝
         * 3 未知状态
         */
        Integer status = 0;
        bookings.setStatus(status);
        save(bookings);
    }

    @Override
    public void updateStatus(UpdateStatusVo updateStatusVo) {
        Integer id = updateStatusVo.getId();
        Integer status = updateStatusVo.getStatus();
        BookingsEntity bookingsEntity = getById(id);
        bookingsEntity.setStatus(status);
        updateById(bookingsEntity);
    }

}